<?php
class ResourceAction extends AdminAction {
    //资源信息图片管理
	public function picture(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$picture = D('PictureView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'get'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
	//	}
		$map['is_dele'] = 0;
		$count = $picture->where($map)->count();
		$page = new Page($count,15);
		$list = $picture->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
 	//资源信息挂图管理
	public function image(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$image = D('ImageView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $image->where($map)->count();
		$page = new Page($count,15);
		$list = $image->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息视频管理
	public function video(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$video = D('VideoView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $video->where($map)->count();
		$page = new Page($count,15);
		$list = $video->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息文章管理
	public function article(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$article = D('ArticleView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $article->where($map)->count();
		$page = new Page($count,15);
		$list = $article->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息图书管理
	public function book(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$book = D('BookView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%') or (`author` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $book->where($map)->count();
		$page = new Page($count,15);
		$list = $book->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息动画管理
	public function flash(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$flash = D('FlashView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $flash->where($map)->count();
		$page = new Page($count,15);
		$list = $flash->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息游戏管理
	public function game(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$game = D('GameView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $game->where($map)->count();
		$page = new Page($count,15);
		$list = $game->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息展品管理
	public function exhibits(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$exhibits = D('ExhibitsView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $exhibits->where($map)->count();
		$page = new Page($count,15);
		$list = $exhibits->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//资源信息知识题管理
	public function knowledge(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$knowledge = D('KnowledgeView');
		//if(strtolower($_SERVER['REQUEST_METHOD']) == 'post'){
			$key = $_GET['searkey'];
			if($key && $key != '请输入搜索关键字'){
				$map['_string'] = "(`code` = '".$key."') or (`title` like '%".$key."%')";
				$this->assign('search','1');
				$this->assign('key',$key);
			}
		//}
		$map['is_dele'] = 0;
		$count = $knowledge->where($map)->count();
		$page = new Page($count,15);
		$list = $knowledge->where($map)->limit($page->firstRow.",".$page->listRows)->order('uploadtime desc')->select();
		$this->assign("page",$page->show());
		$this->assign('list',$list);
		$this->display();
	}
	
	//添加图片资源
	public function addpicture(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
         $model=M('Category');
         $map['status'] = 1;
         $map['catepid'] = 1;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			if($_GET['success']==1){
			 $this->assign('error',$_GET['error']);
			}
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加挂图资源
	public function addimage(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
        $map['catepid'] = 6;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			$this->assign('error',$_GET['error']);
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加视频资源
	public function addvideo(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
         $model=M('Category');
         $map['status'] = 1;
         $map['catepid'] = 2;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			if($_GET['success']==1){
			 $this->assign('error',$_GET['error']);
			}
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加文章资源
	public function addarticle(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
         $model=M('Category');
         $map['status'] = 1;
         $map['catepid'] = 5;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			if($_GET['success']==1){
			 $this->assign('error',$_GET['error']);
			}
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加文章资源
	public function addbook(){
		if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
         $map['catepid'] = 7;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			if($_GET['success']==1){
			$this->assign('error',$_GET['error']);
			}
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加动画资源
	public function addflash(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
         $map['catepid'] = 3;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			$this->assign('error',$_GET['error']);
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加游戏资源
	public function addgame(){
        if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
         $map['catepid'] = 4;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			$this->assign('error',$_GET['error']);
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加展品资源
	public function addexhibits(){
		if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
         $map['catepid'] = 8;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			$this->assign('error',$_GET['error']);
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//添加知识题资源
	public function addknowledge(){
      if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$model=M('Category');
		$map['status'] = 1;
         $map['catepid'] = 9;
		$list=$model->where($map)->select();
		$this->assign('list',$list);
		if($_GET['success']){
			$this->assign('error',$_GET['error']);
			$this->assign('val',$_GET['success']);	
		}else{
			$this->assign('val',0);	
		}
        $this->display();
	}
	
	//图片添加操作
	public function pictureupload() {
        if (!empty($_FILES)) {
	        $files = $_FILES;
	    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Picture/',$files,true,'m_,s_','480,140','400,140');
	        if(is_array($uploadList)){
		    	import("ORG.Util.Image");
		        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
		        $num = count($uploadList);
		        $str = "";
		        $size = "";
		        $area = "";
		        for ( $i=0; $i<$num; $i++){
		        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
			        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 20);
			        $m = $i+1;
			        if ($info[size] < 1048576){
			        	$info[size] = ceil($info[size]/1024) . "KB";
			        }else{
			        	$info[size] = round(($info[size]/1048576),1) . "M";
			        }
			        if($m<$num){
			        	$size .= $info[size].",";
			        	$area .= $info[width] . "x" . $info[height] . ",";
			        	$str .= $uploadList[$i]['savename'].",";
			        }else{
			        	$size .= $info[size];
			        	$area .= $info[width] . "x" . $info[height];
			        	$str .= $uploadList[$i]['savename'];
			        }
		        }
		        $_POST['size'] = $size;
		        $_POST['area'] = $area;
		        $_POST['url'] = $str;
	        }else{
	        	 $this->error($uploadList);
	        }
	        
        	if(($_POST['catepid']!=0)&&(($_POST['cateid']==0)||($_POST['cateid']=='')))
			{
				$_POST['cateid']=$_POST['catepid'];
			 }
	        $model = D('Picture');
	        //保存当前数据对象
	        $data = $_POST;
	        $data['size'] = $_POST['size'];
		    $data['area'] = $_POST['area'];
	        $data['url'] = $_POST['url'];
	         if($model->create($data))
			{
		        $list = $model->add();
		        if ($list !== false) {
		        	$map['pid'] = $list;
		        	$datas['code'] = 'P'.$list;
		        	$lists = $model->where($map)->save($datas);
		            $this->redirect('Resource/addpicture',array('success'=>2));
		        } else {
		        	$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Picture/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/sy_'.$picurl[$i]);
		        	 }
		            $this->redirect('Resource/addpicture',array('success'=>1));
		        }
			}else{
					$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Picture/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Picture/sy_'.$picurl[$i]);
		        	 }
				$this->redirect('Resource/addpicture',array('success'=>1,'error'=>$model->getError()));
			}
        }else{
        	 $this->redirect('Resource/addpicture',array('success'=>1,'error'=>$model->getError()));
        }
    }
    
    //挂图添加操作
	public function imageupload(){
		if (!empty($_FILES)) {
	        $files = $_FILES;
	    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Image/',$files,true,'m_,s_','555,140','645,140');
	        if(is_array($uploadList)){
		    	import("ORG.Util.Image");
		        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
		        $num = count($uploadList);
		        $str = "";
		        $size = "";
		        $area = "";
		        for ( $i=0; $i<$num; $i++){
		        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
			        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 50);
			        $m = $i+1;
		        	if ($info[size] < 1048576){
			        	$info[size] = ceil($info[size]/1024) . "KB";
			        }else{
			        	$info[size] = round(($info[size]/1048576),1) . "M";
			        }
			        if($m<$num){
			        	$size .= $info[size].",";
			        	$area .= $info[width] . "×" . $info[height] . ",";
			        	$str .= $uploadList[$i]['savename'].",";
			        }else{
			        	$size .= $info[size];
			        	$area .= $info[width] . "×" . $info[height];
			        	$str .= $uploadList[$i]['savename'];
			        }
		        }
		        $_POST['size'] = $size;
		        $_POST['area'] = $area;
		        $_POST['url'] = $str;
	        }else{
	        	 $this->error($uploadList);
	        }
	        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
	        $model = D('Image');
	        //保存当前数据对象
	        $data = $_POST;
	        $data['size'] = $_POST['size'];
		    $data['area'] = $_POST['area'];
	        $data['url'] = $_POST['url'];
	         if($model->create($data))
			{
		        $list = $model->add();
		        if ($list !== false) {
		        	$map['iid'] = $list;
		        	$datas['code'] = 'I'.$list;
		        	$lists = $model->where($map)->save($datas);
		            $this->redirect('Resource/addimage',array('success'=>2));
		        } else {
		        	$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Image/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/sy_'.$picurl[$i]);
		        	 }
		            $this->redirect('Resource/addimage',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
					$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Image/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Image/sy_'.$picurl[$i]);
		        	 }
				$this->redirect('Resource/addimage',array('success'=>1,'error'=>$model->getError()));
			}
        }
	}
    
	//视频添加操作
	public function videoupload(){
		if(!empty($_FILES)){
			$imageurl['0'] = $_FILES['imageurl'];
			$url['0'] = $_FILES['url'];
			if ($imageurl['0']['name']){
				$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Video/Image/',$imageurl,true,'m_','140','125');
				if(is_array($imageurlList)){
					 $_POST['imageurl'] = $imageurlList[0]['savename'];
				}else{
	        		 $this->error($imageurlList);
	        	}
			}
	        $urlList = uploadsource('-1','mp4,flv,swf,wmv,avi,rmvb,mpg','./Public/Uploads/Video/',$url);
			if(is_array($urlList)){
				 $_POST['url'] = $urlList[0]['savename'];
			}else{
				unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
	        	$this->error($urlList);
	        }
			if(($_POST['catepid']!=0)&&(($_POST['cateid']==0)||($_POST['cateid']=='')))
			{
				$_POST['cateid']=$_POST['catepid'];
			 }
			$model = D('Video');
	        $data = $_POST;
	        $data['imageurl'] = $_POST['imageurl'];
	        $data['url'] = $_POST['url'];
	        if($model->create($data))
			{
			   	$list = $model->add();
		        if ($list !== false) {
		        	$map['vid'] = $list;
		        	$datas['code'] = 'V'.$list;
		        	$lists = $model->where($map)->save($datas);
		        	$this->redirect('Resource/addvideo',array('success'=>2));
		        } else {
		        	unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
					unlink('./Public/Uploads/Video/'.$_POST['url']);
		             $this->redirect('Resource/addvideo',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
				unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
				unlink('./Public/Uploads/Video/'.$_POST['url']);
				$this->redirect('Resource/addvideo',array('success'=>1,'error'=>$model->getError()));
			}
		}
	}
	
	public function getSwf_word($sourceFile,$destFile){
			
		//echo "begin...<br/>";
			#exec("/usr/local/swftools/bin/pdf2swf qx.pdf -o ok.swf",$arrOut,$retVal);
		$pdflujing=$sourceFile.'.pdf';
		exec("./Public/zhuanhuan/doc2pdf $sourceFile $pdflujing",$arrOut,$retVal);
		exec("./Public/zhuanhuan/pdf2swft $pdflujing $destFile",$arrOut,$retVal);
		//echo "<pre>";
		//print_r($arrOut);
			
		//echo "end...<br/>";
		//echo "retVal: ".$retVal;
		#pclose($fp);
	}
	
	public function getSwf_pdf($sourceFile,$destFile){
			
		//echo "begin...<br/>";
			#exec("/usr/local/swftools/bin/pdf2swf qx.pdf -o ok.swf",$arrOut,$retVal);
		exec("./Public/zhuanhuan/pdf2swft $pdflujing $destFile",$arrOut,$retVal);
		//echo "<pre>";
		//print_r($arrOut);
			
		//echo "end...<br/>";
		//echo "retVal: ".$retVal;
		#pclose($fp);
	}
	
	//文章添加操作
	public function articleupload(){
	if (!empty($_FILES)) {
		 	$imageurl['0'] = $_FILES['imageurl'];
			$url['0'] = $_FILES['url'];
			if ($imageurl['0']['name']){
				$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Article/Image/',$imageurl,true,'m_','140','125');
				if(is_array($imageurlList)){
					 $_POST['imageurl'] = $imageurlList[0]['savename'];
				}else{
		        	 $this->error($imageurlList);
		        }
			}
		 	$uploadList = uploadsource('-1','txt,doc,docx','./Public/Uploads/Article/',$url);
		 	if(is_array($uploadList)){
		 		$_POST['url'] = $uploadList[0]['savename'];
		 	}else{
	            unlink('./Public/Uploads/Article/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Article/Image/m_'.$_POST['imageurl']);
	            $this->error($uploadList);
	        }
	        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
	        $model = D('Article');
	        $data = $_POST;
	        $data['url'] = $_POST['url'];
	        $data['imageurl'] = $_POST['imageurl'];
	        
	       // $sourceFile='./Public/Uploads/Article/'.$_POST['url'];
			//$destFile='./Public/Uploads/Article/Swf/'.$_POST['url'].'.swf';
	 		//if($this->txt2utf8($sourceFile)){
	      //  	$this->getSwf_word($sourceFile,$destFile);
		//	}
	        
	        if($model->create($data))
			{
			   	$list = $model->add();
		        if ($list !== false) {
		        	$map['aid'] = $list;
		        	$datas['code'] = 'A'.$list;
		        	$lists = $model->where($map)->save($datas);
		           $this->redirect('Resource/addarticle',array('success'=>2));
		        } else {
		        	unlink('./Public/Uploads/Article/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Article/Image/m_'.$_POST['imageurl']);
		        	unlink('./Public/Uploads/Article/'.$_POST['url']);
		        	$error=$model->getError();
		            $this->redirect('Resource/addarticle',array('success'=>1,'error'=>$error));
		        }
			}else{
				unlink('./Public/Uploads/Article/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Article/Image/m_'.$_POST['imageurl']);
				unlink('./Public/Uploads/Article/'.$_POST['url']);
				$error=$model->getError();
				$this->redirect('Resource/addarticle',array('success'=>1,'error'=>$error));
			}
		 }
	}
	
	//图书上传操作
	public function bookupload(){
		if(!empty($_FILES)){
			$imageurl['0'] = $_FILES['imageurl'];
			if ($imageurl['0']['name']){
				$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Book/Image/',$imageurl,true,'m_','140','125');
				if(is_array($imageurlList)){
					 $_POST['imageurl'] = $imageurlList[0]['savename'];
				}else{
		        	 $this->error($imageurlList);
		        }
			}
	        $is_open = $_POST['is_open'];
	        if($is_open == 0){
		        $url['0'] = $_FILES['url'];
				$urlList = uploadsource('-1','txt,docx,doc,pdf','./Public/Uploads/Book/',$url);
				if(is_array($urlList)){
					 $_POST['url'] = $urlList[0]['savename'];
				}else{
					unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
		        	$this->error($urlList);
		        }
	        }else{
	        	 $_POST['url'] = "";
	        }
	        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
			$model = D('Book');
	        $data = $_POST;
	        $data['imageurl'] = $_POST['imageurl'];
	        $data['url'] = $_POST['url'];
		 	if($data['url']){
	        	$data['type'] = pathinfo($data['url'], PATHINFO_EXTENSION);
			}else{
	        	$data['type'] = "";
			}
	        if($model->create($data))
			{
			   	$list = $model->add();
		        if ($list !== false) {
		        	$map['bid'] = $list;
		        	$datas['code'] = 'B'.$list;
		        	$lists = $model->where($map)->save($datas);
		        	$this->redirect('Resource/addbook',array('success'=>2));
		        } else {
		        	unlink('./Public/Uploads/Book/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Book/Image/m_'.$_POST['imageurl']);
					if($is_open == 0){
						unlink('./Public/Uploads/Book/'.$_POST['url']);
					}
		            $this->redirect('Resource/addbook',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
				unlink('./Public/Uploads/Book/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Book/Image/m_'.$_POST['imageurl']);
				if($is_open == 0){
					unlink('./Public/Uploads/Book/'.$_POST['url']);
				}
				 $this->redirect('Resource/addbook',array('success'=>1,'error'=>$model->getError()));
			}
		}
		
	}
	
	//动漫上传操作
	public function  flashupload(){
		    if(!empty($_FILES)){
			$imageurl['0'] = $_FILES['imageurl'];
			$url['0'] = $_FILES['url'];
			if ($imageurl['0']['name']){
				$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Flash/Image/',$imageurl,true,'m_','140','125');
				if(is_array($imageurlList)){
					 $_POST['imageurl'] = $imageurlList[0]['savename'];
				}else{
		        	 $this->error($imageurlList);
		        }
			}
			$urlList = uploadsource('-1','mp4,flv,swf,wmv,avi,rmvb,mpg','./Public/Uploads/Flash/',$url);
			if(is_array($urlList)){
				 $_POST['url'] = $urlList[0]['savename'];
			}else{
				unlink('./Public/Uploads/Flash/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Flash/Image/m_'.$_POST['imageurl']);
	        	$this->error($urlList);
	        }
	       if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
			$model = D('Flash');
	        $data = $_POST;
	        $data['imageurl'] = $_POST['imageurl'];
	        $data['url'] = $_POST['url'];
	        if($model->create($data))
			{   
			   	$list = $model->add();
		        if ($list !== false) {
		        	$map['flaid'] = $list;
		        	$datas['code'] = 'F'.$list;
		        	$lists = $model->where($map)->save($datas);
		        	$this->redirect('Resource/addflash',array('success'=>2));
		        	//$this->success('上传动画成功！');
		        } else {
		        	unlink('./Public/Uploads/Flash/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Flash/Image/m_'.$_POST['imageurl']);
					unlink('./Public/Uploads/Flash/'.$_POST['url']);
		           $this->redirect('Resource/addflash',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
				unlink('./Public/Uploads/Flash/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Flash/Image/m_'.$_POST['imageurl']);
				unlink('./Public/Uploads/Flash/'.$_POST['url']);
				$this->redirect('Resource/addflash',array('success'=>1,'error'=>$model->getError()));
			}
		}
	}
	
	//游戏上传操作
	public function gameupload(){
	 	if(!empty($_FILES)){
	    $imageurl[0]=$_FILES['imageurl'];
	    $url['0']=$_FILES['url'];
	    if ($imageurl['0']['name']){
		    $imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Game/Image/',$imageurl,true,'m_','140','125');
	        if(is_array($imageurlList)){
	             $_POST['imageurl']=$imageurlList[0]['savename'];
	        }else{
	              $this->error($imageurlList);
	        }
	    }
        $urlList = uploadsource('-1','flv,swf','./Public/Uploads/Game/',$url);
        if(is_array($urlList)){
                $_POST['url']=$urlList[0]['savename'];
        }else{
        		unlink('./Public/Uploads/Game/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Game/Image/m_'.$_POST['imageurl']);
	        	$this->error($urlList);
        }
        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
        $model=D('Game');
        $data=$_POST;
        if($model->create($data)){
           $list=$model->add();
          if($list){
          			$map['gid'] = $list;
		        	$datas['code'] = 'G'.$list;
		        	$lists = $model->where($map)->save($datas);
                    $this->redirect('Resource/addgame',array('success'=>2));
        }else{
		            unlink('./Public/Uploads/Game/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Game/Image/m_'.$_POST['imageurl']);
					unlink('./Public/Uploads/Game/'.$_POST['url']);
					$this->redirect('Resource/addgame',array('success'=>1,'error'=>$model->getError()));
        }
	   }else{
	          unlink('./Public/Uploads/Game/Image/'.$_POST['imageurl']);
			  unlink('./Public/Uploads/Game/Image/m_'.$_POST['imageurl']);
			  unlink('./Public/Uploads/Game/'.$_POST['url']);
			  $this->redirect('Resource/addgame',array('success'=>1,'error'=>$model->getError()));
	   }
	  }
    }
    
    //展品上传操作
	public function exhibitsupload() {
        if (!empty($_FILES)) {
	        $files = $_FILES;
	    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Exhibits/',$files,true,'m_,s_','480,140','400,140');
	        if(is_array($uploadList)){
		    	import("ORG.Util.Image");
              //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
		        $num = count($uploadList);
		        $str = "";
		        $size = "";
		        $area = "";
		        for ( $i=0; $i<$num; $i++){
			        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 50);
			        $info = Image::getImageInfo($uploadList[$i]['savepath'].$uploadList[$i]['savename']);
		    	    $m = $i+1;
		        	if ($info[size] < 1048576){
			        	$info[size] = ceil($info[size]/1024) . "KB";
			        }else{
			        	$info[size] = round(($info[size]/1048576),1) . "M";
			        }
			        if($m<$num){                        
                        $size.=$uploadList[$i]['size'].",";
			        	$str .= $uploadList[$i]['savename'].",";
                        $area.=$info['height'].'×'.$info['width'].',';

			        }else{			           
                        $size.=$uploadList[$i]['size'];
			        	$str .= $uploadList[$i]['savename'];
	                    $area.=$info['height'].'×'.$info['width'];
                        }
		        }
		        $_POST['url'] = $str;
		        $_POST['area']=$area;
		        $_POST['size']=$size;
	        }else{
	        	 $this->error($uploadList);
	        }
	         if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
	        $model = D('Exhibits');
	        //保存当前数据对象
	        $data = $_POST;
	        $data['size'] = $_POST['size'];
		    $data['area'] = $_POST['area'];
	        $data['url'] = $_POST['url'];
	         if($model->create($data))
			{
		        $list = $model->add();
                if ($list !== false) {
		        	$map['eid'] = $list;
		        	$datas['code'] = 'E'.$list;
		        	$lists = $model->where($map)->save($datas);
		            $this->redirect('Resource/addexhibits',array('success'=>2));
		        } else {
		        	$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Exhibits/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/sy_'.$picurl[$i]);
		        	 }
		             $this->redirect('Resource/addexhibits',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
					$picurl = explode(',', $_POST['url']);
		        	$num = count($picurl);
		        	 for ( $i=0; $i<$num; $i++){
		        	 	unlink('./Public/Uploads/Exhibits/'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/m_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/s_'.$picurl[$i]);
		        	 	unlink('./Public/Uploads/Exhibits/sy_'.$picurl[$i]);
		        	 }
				   $this->redirect('Resource/addexhibits',array('success'=>1,'error'=>$model->getError()));
			}
        }
    }
	
    //知识题上传操作
	public function knowledgeupload(){
		   if(!empty($_FILES)){
				$imageurl['0'] = $_FILES['imageurl'];
				$url['0'] = $_FILES['url'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Knowledge/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
			        	 $this->error($imageurlList);
			        }
				}
			$urlList = uploadsource('-1','doc,txt,docx','./Public/Uploads/Knowledge/',$url);
			if(is_array($urlList)){
				 $_POST['url'] = $urlList[0]['savename'];
			}else{
				unlink('./Public/Uploads/Knowledge/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Knowledge/Image/m_'.$_POST['imageurl']);
	        	$this->error($urlList);
	        }
			
			$model = D('Knowledge');
	        $data = $_POST;
	        $data['imageurl'] = $_POST['imageurl'];
	        $data['url'] = $_POST['url'];
	        /*
	        $sourceFile='./Public/Uploads/Knowledge/'.$_POST['url'];
			$destFile='./Public/Uploads/Knowledge/Swf/'.$_POST['url'].'.swf';
		    if($this->txt2utf8($sourceFile)){
	        	$this->getSwf_word($sourceFile,$destFile);
			}*/
	        
	        if($model->create($data))
			{   
			   	$list = $model->add();
		        if ($list !== false) {
		        	$map['kid'] = $list;
		        	$datas['code'] = 'k'.$list;
		        	$lists = $model->where($map)->save($datas);
		        	$this->redirect('Resource/addknowledge',array('success'=>2));
		        } else {
		        	unlink('./Public/Uploads/Knowledge/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Knowledge/Image/m_'.$_POST['imageurl']);
					unlink('./Public/Uploads/Knowledge/'.$_POST['url']);
		             $this->redirect('Resource/addknowledge',array('success'=>1,'error'=>$model->getError()));
		        }
			}else{
				unlink('./Public/Uploads/Knowledge/Image/'.$_POST['imageurl']);
				unlink('./Public/Uploads/Knowledge/Image/m_'.$_POST['imageurl']);
				unlink('./Public/Uploads/Knowledge/'.$_POST['url']);
				$this->redirect('Resource/addknowledge',array('success'=>1,'error'=>$model->getError()));
			}
		}
	}
    
	//编辑图片资源
	public function editpicture(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$pid = $_GET['pid'];
		if($pid){
			$picture = D('Picture');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$files = $_FILES;
				if($files['url']['name']['0']){
			    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Picture/',$files,true,'m_,s_','460,385','140,125');
			        if(is_array($uploadList)){
				    	import("ORG.Util.Image");
				        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
				        $num = count($uploadList);
				        $str = "";
				        $size = "";
				        $area = "";
				        for ( $i=0; $i<$num; $i++){
				        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
					        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 20);
					        $m = $i+1;
					        if ($info[size] < 1048576){
					        	$info[size] = ceil($info[size]/1024) . "KB";
					        }else{
					        	$info[size] = round(($info[size]/1048576),1) . "M";
					        }
					        if($m<$num){
					        	$size .= $info[size].",";
					        	$area .= $info[width] . "x" . $info[height] . ",";
					        	$str .= $uploadList[$i]['savename'].",";
					        }else{
					        	$size .= $info[size];
					        	$area .= $info[width] . "x" . $info[height];
					        	$str .= $uploadList[$i]['savename'];
					        }
				        }
				        $_POST['size'] = $size;
				        $_POST['area'] = $area;
				        $_POST['url'] = $str;
			        }else{
			        	 $this->error($uploadList);
			        }
				}
				
			        if(($_POST['catepid']!=0)&&(($_POST['cateid']==0)||($_POST['cateid']=='')))
			        {
			        	$_POST['cateid']=$_POST['catepid'];
			        }
				$data = array(
					"pid"=>$_GET['pid'],
					"title"=>$_POST['title'],
					"cateid"=>$_POST['cateid'],
					"keyword"=>$_POST['keyword'],
					"size" => $_POST['size'],
		    		"area" => $_POST['area'],
	        		"url" => $_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($picture->create($data)){
					if($picture->save()){
						$this->success('编辑成功',U('Resource/picture'));
					}else{
						$this->success('无编辑',U('Resource/picture'));
					}
				}else{
					$this->error($picture->getError(),U('Resource/picture'));
				}
			}else{
				if($_GET['success']){
				if($_GET['success']==1){
					$this->assign('error',$_GET['error']);
				}
					$this->assign('val',$_GET['success']);	
				}else{
					$this->assign('val',0);	
				}
				$model=M('Category');
				$list=$model->where('`catepid`=1')->select();
				$this->assign('list',$list);
				$map['pid'] = $pid;
				$info = $picture->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 1){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				$this->assign('info',$info);
				$this->assign('pid',$pid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/picture);
		}
	}
	
	//编辑挂图资源
	public function editimage(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$iid = $_GET['iid'];
		if($iid){
			$image = D('Image');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$files = $_FILES;
				if($files['url']['name']['0']){
		    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Image/',$files,true,'m_,s_','555,385','645,125');
		        if(is_array($uploadList)){
			    	import("ORG.Util.Image");
			        //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
			        $num = count($uploadList);
			        $str = "";
			        $size = "";
			        $area = "";
			        for ( $i=0; $i<$num; $i++){
			        	$info = Image::getImageInfo($uploadList[$i]['savepath'] . $uploadList[$i]['savename']);
				        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 50);
				        $m = $i+1;
			        	if ($info[size] < 1048576){
				        	$info[size] = ceil($info[size]/1024) . "KB";
				        }else{
				        	$info[size] = round(($info[size]/1048576),1) . "M";
				        }
				        if($m<$num){
				        	$size .= $info[size].",";
				        	$area .= $info[width] . "×" . $info[height] . ",";
				        	$str .= $uploadList[$i]['savename'].",";
				        }else{
				        	$size .= $info[size];
				        	$area .= $info[width] . "×" . $info[height];
				        	$str .= $uploadList[$i]['savename'];
				        }
			        }
			        $_POST['size'] = $size;
			        $_POST['area'] = $area;
			        $_POST['url'] = $str;
		        }else{
		        	 $this->error($uploadList);
		        }
				}
	        	if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				$data = array(
					"iid"=>$_GET['iid'],
					"title"=>$_POST['title'],
					"cateid"=>$_POST['cateid'],
					"keyword"=>$_POST['keyword'],
					"size" => $_POST['size'],
		    		"area" => $_POST['area'],
	        		"url" => $_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($image->create($data)){
					if($image->save()){
						$this->success('编辑成功',U('Resource/image'));
					}else{
						$this->success('无编辑',U('Resource/image'));
					}
				}else{
					$this->error($image->getError(),U('Resource/image'));
				}
			}else{
				$map['iid'] = $iid;
				$info = $image->where($map)->find();
				
				$this->assign('info',$info);
				$this->assign('iid',$iid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/image);
		}
	}
    
	//编辑视频资源
	public function editvideo(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$vid = $_GET['vid'];
		
			if($vid)
			{
				$video = D('Video');
				if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
				{
				$imageurl['0'] = $_FILES['imageurl'];
				$url['0'] = $_FILES['url'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Video/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
		        		 $this->error($imageurlList);
		        	}
				}
				if($url['0']['name']){
		        $urlList = uploadsource('-1','mp4,flv,swf,wmv,avi,rmvb,mpg','./Public/Uploads/Video/',$url);
				if(is_array($urlList)){
					 $_POST['url'] = $urlList[0]['savename'];
				}else{
					unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
		        	$this->error($urlList);
		        }
				}
				if(($_POST['catepid']!=0)&&(($_POST['cateid']==0)||($_POST['cateid']=='')))
				{
					$_POST['cateid']=$_POST['catepid'];
				 }
				
				if(($_POST['catepid']!=0)&&(($_POST['cateid']==0)||($_POST['cateid']=='')))
				{
					$_POST['cateid']=$_POST['catepid'];
				}
				$data = array(
					"vid"=>$_GET['vid'],
					"title"=>$_POST['title'],
					"imageurl"=>$_POST['imageurl'],
					"keyword"=>$_POST['keyword'],
					"cateid"=>$_POST['cateid'],
					"url"=>$_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($video->create($data)){
					if($video->save()){
						$this->success('编辑成功',U('Resource/video'));
					}else{
						$this->success('无编辑',U('Resource/video'));
					}
				}else{
					$this->error($video->getError(),U('Resource/video'));
				}
				}else{
				if($_GET['success']){
				if($_GET['success']==1){
					$this->assign('error',$_GET['error']);
				}
					$this->assign('val',$_GET['success']);	
				}else{
					$this->assign('val',0);	
				}
				$model=M('Category');
				$list=$model->where('`catepid`=2')->select();
				$this->assign('list',$list);
				$map['vid'] = $vid;
				$info = $video->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 2){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				
				$this->assign('info',$info);
				$this->assign('vid',$vid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/video);
		}
	}
	
	//编辑文章资源
	public function editarticle(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$aid = $_GET['aid'];
		if($aid){
			$article = D('Article');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$imageurl['0'] = $_FILES['imageurl'];
				$url['0'] = $_FILES['url'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Article/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
			        	 $this->error($imageurlList);
			        }
				}
				if($url['0']['name']){
			 	$uploadList = uploadsource('-1','txt,doc,docx,pdf','./Public/Uploads/Article/',$url);
			 	if(is_array($uploadList)){
			 		$_POST['url'] = $uploadList[0]['savename'];
			 		$_POST['status'] = 0;
			 	}else{
		            unlink('./Public/Uploads/Article/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Article/Image/m_'.$_POST['imageurl']);
		            $this->error($uploadList);
		        }
		        /* $sourceFile='./Public/Uploads/Article/'.$_POST['url'];
				$destFile='./Public/Uploads/Article/Swf/'.$_POST['url'].'.swf';
				if($this->txt2utf8($sourceFile)){
	        	$this->getSwf_word($sourceFile,$destFile);
				}*/

				}
		        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				$data = array(
					"aid"=>$_GET['aid'],
					"title"=>$_POST['title'],
					"author"=>$_POST['author'],
					"imageurl"=>$_POST['imageurl'],
					"keyword"=>$_POST['keyword'],
					"cateid"=>$_POST['cateid'],
					"url"=>$_POST['url'],
					"desc"=>$_POST['desc'],
					"status"=>$_POST['status'],
					"downscore"=>$_POST['downscore'],
				);
				if($article->create($data)){
					if($article->save()){
						$this->success('编辑成功',U('Resource/article'));
					}else{
						$this->success('无编辑',U('Resource/article'));
					}
				}else{
					$this->error($article->getError(),U('Resource/article'));
				}
			}else{
				$model=M('Category');
				$list=$model->where('`catepid`=5')->select();
				$this->assign('list',$list);
				$map['aid'] = $aid;
				$info = $article->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 5){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				$this->assign('info',$info);
				$this->assign('aid',$aid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/article);
		}
	}
	
	//编辑图书资源
	public function editbook(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$bid = $_GET['bid'];
		if($bid){
			$book = D('Book');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$imageurl['0'] = $_FILES['imageurl'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Book/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
			        	 $this->error($imageurlList);
			        }
				}
		        $is_open = $_POST['is_open'];
		        if($is_open == 0){
			        $url['0'] = $_FILES['url'];
			        if($url['0']['name']){
					$urlList = uploadsource('-1','txt,docx,doc,pdf','./Public/Uploads/Book/',$url);
					if(is_array($urlList)){
						 $_POST['url'] = $urlList[0]['savename'];
					}else{
						unlink('./Public/Uploads/Video/Image/'.$_POST['imageurl']);
						unlink('./Public/Uploads/Video/Image/m_'.$_POST['imageurl']);
			        	$this->error($urlList);
			        }
			        }
		        }else{
		        	 $_POST['url'] = "";
		        }
		        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				 if($_POST['url']){
		        	$_POST['type'] = pathinfo($_POST['url'], PATHINFO_EXTENSION);
				}else{
		        	$_POST['type'] = "";
				}
				$data = array(
					"bid"=>$_GET['bid'],
					"title"=>$_POST['title'],
					"author"=>$_POST['author'],
					"imageurl"=>$_POST['imageurl'],
					"cateid"=>$_POST['cateid'],
					"keyword"=>$_POST['keyword'],
					"is_open"=>$_POST['is_open'],
					"url"=>$_POST['url'],
					"publish"=>$_POST['publish'],
					"publishurl"=>$_POST['publishurl'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
					"type"=>$_POST['type'],
				);
				if($book->create($data)){
					if($book->save()){
						$this->success('编辑成功',U('Resource/book'));
					}else{
						$this->success('无编辑',U('Resource/book'));
					}
				}else{
					$this->error($book->getError(),U('Resource/book'));
				}
			}else{
				$model=M('Category');
				$list=$model->where('`catepid`=7')->select();
				$this->assign('list',$list);
				$map['bid'] = $bid;
				$info = $book->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 7){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				$this->assign('info',$info);
				$this->assign('bid',$bid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/book);
		}
	}
	
	//编辑动漫资源
	public function editflash(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$flaid = $_GET['flaid'];
		if($flaid){
			$flash = M('Flash');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$imageurl['0'] = $_FILES['imageurl'];
				$url['0'] = $_FILES['url'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Flash/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
			        	 $this->error($imageurlList);
			        }
				}
				if($url['0']['name']){
				$urlList = uploadsource('-1','mp4,flv,swf,wmv,avi,rmvb,mpg','./Public/Uploads/Flash/',$url);
				if(is_array($urlList)){
					 $_POST['url'] = $urlList[0]['savename'];
				}else{
					unlink('./Public/Uploads/Flash/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Flash/Image/m_'.$_POST['imageurl']);
		        	$this->error($urlList);
		        }
				}
		       if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				$data = array(
					"flaid"=>$_GET['flaid'],
					"title"=>$_POST['title'],
					"imageurl"=>$_POST['imageurl'],
					"keyword"=>$_POST['keyword'],
					"cateid"=>$_POST['cateid'],
					"url"=>$_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($flash->create($data)){
					if($flash->save()){
						$this->success('编辑成功',U('Resource/flash'));
					}else{
						$this->success('无编辑',U('Resource/flash'));
					}
				}else{
					$this->error($flash->getError(),U('Resource/flash'));
				}
			}else{
				$model=M('Category');
				$list=$model->where('`catepid`=3')->select();
				$this->assign('list',$list);
				$map['flaid'] = $flaid;
				$info = $flash->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 3){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				$this->assign('info',$info);
				$this->assign('flaid',$flaid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/flash);
		}
	}
	
	//编辑游戏资源
	public function editgame(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$gid = $_GET['gid'];
		if($gid){
			$game = D('Game');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$imageurl[0]=$_FILES['imageurl'];
			    $url['0']=$_FILES['url'];
			    if ($imageurl['0']['name']){
				    $imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Game/Image/',$imageurl,true,'m_','140','125');
			        if(is_array($imageurlList)){
			             $_POST['imageurl']=$imageurlList[0]['savename'];
			        }else{
			              $this->error($imageurlList);
			        }
			    }
			    if($url['0']['name']){
		        $urlList = uploadsource('-1','flv,swf','./Public/Uploads/Game/',$url);
		        if(is_array($urlList)){
		                $_POST['url']=$urlList[0]['savename'];
		        }else{
		        		unlink('./Public/Uploads/Game/Image/'.$_POST['imageurl']);
						unlink('./Public/Uploads/Game/Image/m_'.$_POST['imageurl']);
			        	$this->error($urlList);
		        }
			    }
		        if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				$data = array(
					"gid"=>$_GET['gid'],
					"title"=>$_POST['title'],
					"imageurl"=>$_POST['imageurl'],
					"keyword"=>$_POST['keyword'],
					"cateid"=>$_POST['cateid'],
					"url"=>$_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($game->create($data)){
					if($game->save()){
						$this->success('编辑成功',U('Resource/game'));
					}else{
						$this->success('无编辑',U('Resource/game'));
					}
				}else{
					$this->error($game->getError(),U('Resource/game'));
				}
			}else{
				$model=M('Category');
				$list=$model->where('`catepid`=4')->select();
				$this->assign('list',$list);
				$map['gid'] = $gid;
				$info = $game->where($map)->find();
				$mapj['cateid'] = $info['cateid'];
				$catpid = $model->where($mapj)->find();
				if($catpid['catepid'] == 4){
					$this->assign('status',0);
				}
				elseif ($catpid['catepid'] == 0)
				{
					$this->assign('status',1);
				}
				else{
					$mapm['catepid'] = $catpid['catepid'];
					$listx=$model->where($mapm)->select();
					$this->assign('listx',$listx);
					$this->assign('status',2);
					$this->assign('catepid',$catpid['catepid']);
				}
				$this->assign('info',$info);
				$this->assign('gid',$gid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/game);
		}
	}
	
	//编辑展品资源
	public function editexhibits(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$eid = $_GET['eid'];
		if($eid){
			$exhibits =D('Exhibits');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$files = $_FILES;
				if($files['url']['name']['0']){
		    	$uploadList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Exhibits/',$files,true,'m_,s_','460,385','140,125');
		        if(is_array($uploadList)){
			    	import("ORG.Util.Image");
	              //给m_缩略图添加水印, Image::water('原文件名','水印图片地址')
			        $num = count($uploadList);
			        $str = "";
			        $size = "";
			        $area = "";
			        for ( $i=0; $i<$num; $i++){
				        Image::water($uploadList[$i]['savepath'] . '' . $uploadList[$i]['savename'], './Public/Images/logo.jpg', $uploadList[$i]['savepath'] .'sy_' . $uploadList[$i]['savename'], 50);
				        $info = Image::getImageInfo($uploadList[$i]['savepath'].$uploadList[$i]['savename']);
			    	    $m = $i+1;
			        	if ($info[size] < 1048576){
				        	$info[size] = ceil($info[size]/1024) . "KB";
				        }else{
				        	$info[size] = round(($info[size]/1048576),1) . "M";
				        }
				        if($m<$num){                        
	                        $size.=$uploadList[$i]['size'].",";
				        	$str .= $uploadList[$i]['savename'].",";
	                        $area.=$info['height'].'×'.$info['width'].',';
	
				        }else{			           
	                        $size.=$uploadList[$i]['size'];
				        	$str .= $uploadList[$i]['savename'];
		                    $area.=$info['height'].'×'.$info['width'];
	                        }
			        }
			        $_POST['url'] = $str;
			        $_POST['area']=$area;
			        $_POST['size']=$size;
		        }else{
		        	 $this->error($uploadList);
		        }
				}
		         if(empty($_POST['cateid']))  $_POST['cateid']=$_POST['catepid'];
				$data = array(
					"eid"=>$_GET['eid'],
					"title"=>$_POST['title'],
					"cateid"=>$_POST['cateid'],
					"keyword"=>$_POST['keyword'],
					"size" => $_POST['size'],
		    		"area" => $_POST['area'],
	        		"url" => $_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
				);
				if($exhibits->create($data)){
					if($exhibits->save()){
						$this->success('编辑成功',U('Resource/exhibits'));
					}else{
						$this->success('无编辑',U('Resource/exhibits'));
					}
				}else{
					$this->error($exhibits->getError(),U('Resource/exhibits'));
				}
			}else{
				$map['eid'] = $eid;
				$info = $exhibits->where($map)->find();
				$this->assign('info',$info);
				$this->assign('eid',$eid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/exhibits);
		}
	}
	
	//编辑知识题资源
	public function editknowledge(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$kid = $_GET['kid'];
		if($kid){
			$knowledge = D('Knowledge');
			if(strtolower($_SERVER['REQUEST_METHOD']) == 'post')
			{
				$imageurl['0'] = $_FILES['imageurl'];
				$url['0'] = $_FILES['url'];
				if ($imageurl['0']['name']){
					$imageurlList = uploadsource('-1','jpg,gif,png,jpeg','./Public/Uploads/Knowledge/Image/',$imageurl,true,'m_','140','125');
					if(is_array($imageurlList)){
						 $_POST['imageurl'] = $imageurlList[0]['savename'];
					}else{
			        	 $this->error($imageurlList);
			        }
				}
				if($url['0']['name']){
				$urlList = uploadsource('-1','doc,txt,docx,pdf','./Public/Uploads/Knowledge/',$url);
				if(is_array($urlList)){
					 $_POST['url'] = $urlList[0]['savename'];
					 $_POST['status'] = 0;
				}else{
					unlink('./Public/Uploads/Knowledge/Image/'.$_POST['imageurl']);
					unlink('./Public/Uploads/Knowledge/Image/m_'.$_POST['imageurl']);
		        	$this->error($urlList);
		        }
						        
		    /*$sourceFile='./Public/Uploads/Knowledge/'.$_POST['url'];
			$destFile='./Public/Uploads/Knowledge/Swf/'.$_POST['url'].'.swf';
			if($this->txt2utf8($sourceFile)){
	        	$this->getSwf_word($sourceFile,$destFile);
			}*/
			}
				$data = array(
					"kid"=>$_GET['kid'],
					"title"=>$_POST['title'],
					"imageurl"=>$_POST['imageurl'],
					"keyword"=>$_POST['keyword'],
					"url"=>$_POST['url'],
					"desc"=>$_POST['desc'],
					"downscore"=>$_POST['downscore'],
					"status"=>$_POST['status'],
				);
				if($knowledge->create($data)){
					if($knowledge->save()){
						$this->success('编辑成功',U('Resource/knowledge'));
					}else{
						$this->success('无编辑',U('Resource/knowledge'));
					}
				}else{
					$this->error($knowledge->getError(),U('Resource/knowledge'));
				}
			}else{
				$map['kid'] = $kid;
				$info = $knowledge->where($map)->find();
				$this->assign('info',$info);
				$this->assign('kid',$kid);
				$this->display();
			}
		}else{
			$this->redirect(Resource/knowledge);
		}
	}
	
	//查看图片资源
	public function lookpicture(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$pid = $_GET['pid'];
		$map['pid'] = $pid;
		$info = M('Picture')->where($map)->find();
		$file_dir="./Public/Uploads/Picture/";
		$url = explode(',', $info['url']);
		download($file_dir,$url['0'],$info['title']);
		$this->redirect(Resource/picture);
	}
	
	//查看视频资源
	public function lookvideo(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$vid = $_GET['vid'];
		$map['vid'] = $vid;
		$info = M('Video')->where($map)->find();
		$file_dir="./Public/Uploads/Video/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/video);
	}
	
	//查看动画资源
	public function lookflash(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$flaid = $_GET['flaid'];
		$map['flaid'] = $flaid;
		$info = M('Flash')->where($map)->find();
		$file_dir="./Public/Uploads/Flash/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/flash);
	}
	
	//查看游戏资源
	public function lookgame(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$gid = $_GET['gid'];
		$map['gid'] = $gid;
		$info = M('Game')->where($map)->find();
		$file_dir="./Public/Uploads/Game/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/game);
	}
	
	//查看文章资源
	public function lookarticle(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$aid = $_GET['aid'];
		$map['aid'] = $aid;
		$info = M('Article')->where($map)->find();
		$file_dir="./Public/Uploads/Article/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/article);
	}
	
	//查看挂图资源
	public function lookimage(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$iid = $_GET['iid'];
		$map['iid'] = $iid;
		$info = M('Image')->where($map)->find();
		$file_dir="./Public/Uploads/Image/";
		$url = explode(',', $info['url']);
		download($file_dir,$url['0'],$info['title']);
		$this->redirect(Resource/image);
	}
	
	//查看图书资源
	public function lookbook(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$bid = $_GET['bid'];
		$map['bid'] = $bid;
		$info = M('Book')->where($map)->find();
		$file_dir="./Public/Uploads/Book/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/book);
	}
	
	//查看展品资源
	public function lookexhibits(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$eid = $_GET['eid'];
		$map['eid'] = $eid;
		$info = M('Exhibits')->where($map)->find();
		$file_dir="./Public/Uploads/Exhibits/";
		$url = explode(',', $info['url']);
		download($file_dir,$url['0'],$info['title']);
		$this->redirect(Resource/exhibits);
	}
	
	//查看知识题资源
	public function lookknowledge(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$kid = $_GET['kid'];
		$map['kid'] = $kid;
		$info = M('Knowledge')->where($map)->find();
		$file_dir="./Public/Uploads/Knowledge/";
		download($file_dir,$info['url'],$info['title']);
		$this->redirect(Resource/knowledge);
	}
		
	//资源删除
	public function dele(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$pid = $_POST['pid'];
		$model = $_POST['model'];
		$key = $_POST['key'];
		if($pid && $model && $key)
		
		{
			$map[$key] = $pid;
			$data['is_dele'] = 1;
			$res = M($model)->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}
		else echo 0;
	}
	
	//资源信息审核
	public function enable()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$pid = $_POST['pid'];
		$type = $_POST['type'];
		$model = $_POST['model'];
		$key = $_POST['key'];
		if($pid && $type && $model && $key)
		{
			$map[$key] = $pid;
			$map['is_dele'] = 0;
			$data[$type] = 1;
			$model=M($model);
			$res = $model->where($map)->save($data);
			if($type == 'status'){
			    $uap[$key] = $pid;
				$puser=$model->where($uap)->Field('uid,code,title')->find();
				$reason="上传'".$puser['title']."'";
				income($puser['uid'],10,$reason,$puser['code']);
			}
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	
	public function forbidden()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$pid = $_POST['pid'];
		$type = $_POST['type'];
		$model = $_POST['model'];
		$key = $_POST['key'];
		if($pid && $type && $model && $key)
		{
			$model=M($model);
			$map[$key] = $pid;
			$map['is_dele'] = 0;
			$data[$type] = 0;
			$res = $model->where($map)->save($data);
			//	$uap[$key] = $pid;
			//	$puser=$model->where($uap)->Field('uid,code,title')->find();
			//	$reason="上传'".$puser['title']."'";
			//	income($puser['uid'],-10,$reason,$puser['code']);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	public function enable1()
	{

			$isLogin = session(C('ADMIN_AUTH_KEY'));
			if(!$isLogin) $this->redirect('User/login');
			$pid = $_GET['pid'];
			$type = $_GET['type'];
			$model = $_GET['model'];
			$key = $_GET['key'];
			if($pid && $type && $model && $key)
			{
				$map[$key] = $pid;
				$map['is_dele'] = 0;
				$data[$type] = 1;
				if(($model == 'Article' || $model == 'Knowledge') && $type == 'status'){
					$url = M($model)->field('url')->where($map)->find();
					if($url['url']){
						import("ORG.Util.Ftp");
						$config = array(
							'hostname' => '192.168.0.232',
							'username' => 'xww',
							'password' => '123456',
							'port' => 21
						);
						$ftp = new Ftp();
						$content = $ftp->connect($config);
						if($content){
							$filename = $url['url'];
							$sourceFile = './Public/Uploads/'.$model.'/'.$filename;
							if($this->txt2utf8($sourceFile)){
								$furl = './Public/Uploads/'.$model.'/';
								$status = ($ftp->upload($furl.$filename,'word2pdf/'.$filename));
							}
							if($status){
								import('ORG.Util.Snoopy');

								$qString='ex/15.php?file='.$filename.'&model='.$model.'&pid='.$pid.'&key='.$key.'&type='.$type;
								$sendurl = "http://{$config['hostname']}/{$qString}";
								$sny=new snoopy();
								$sny->timeout=20;
								$sny->fetch($sendurl);
								$result=$sny->results;
								$this->dealRecv($result);
							
																
							}else{
								$modeltp = "Resource/".strtolower($model);
								$this->redirect($modeltp);
							}
						}else{
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}
					}
				
				}else{
					$model1=M($model);
					$res = $model1->where($map)->save($data);
					$uap[$key] = $pid;
					$puser=$model1->where($uap)->Field('uid,code,title')->find();
					$reason="上传'".$puser['title']."'";
					income($puser['uid'],10,$reason,$puser['code']);
					if($res){
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}else{
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}
				}
			}else{
				
					$modeltp = "Resource/".strtolower($model);
					$this->redirect($modeltp);
			}			
		
	}
	

	public function dealRecv($arr){
	
		$arr=substr($arr,3,strlen($arr)-3);
		$array = $this->getarr($arr);
		
		if($array['sta'] > 0){
					
			if($array['sta'] ==1 ){

				$model = $array['model'];
				$filename = $array['file'];
				$pid = $array['pid'];
				$img = $array['img'];
				$key = $array['key'];
				$type = $array['type'];			

				$purl = './Public/Uploads/'.$model.'/'.$filename;
				$destFile='./Public/Uploads/'.$model.'/Swf/'.$filename.'.swf';
				
				$stau = $this->getSwf($purl,$destFile);
			
				if(!$stau){
					if($this->insertname($pid,$img,$model,$key)){
						$data[$type] = 1;
						$map[$key] = $pid;
						if(M($model)->where($map)->save($data)){
							$uap[$key] = $pid;
							$puser=M($model)->where($uap)->Field('uid,code,title')->find();
							$reason="上传'".$puser['title']."'";
							income($puser['uid'],10,$reason,$puser['code']);
							
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}else{
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}
					}else{
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}
				}else{
					$modeltp = "Resource/".strtolower($model);
					$this->redirect($modeltp);
				}
			}else{
				$modeltp = "Resource/".strtolower($model);
				$this->redirect($modeltp);
			}
		}
		
	}
	
	public function enable2()
	{

		if($_GET['sta'] > 0){
			if($_GET['sta'] ==1 ){
				$model = $_GET['model'];
				$filename = $_GET['file'];
				$pid = $_GET['pid'];
				$img = $_GET['img'];
				$key = $_GET['key'];
				$type = $_GET['type'];
				$purl = './Public/Uploads/'.$model.'/'.$filename;
				$destFile='./Public/Uploads/'.$model.'/Swf/'.$filename.'.swf';
				$stau = $this->getSwf($purl,$destFile);
				if(!$stau){
					if($this->insertname($pid,$img,$model,$key)){
						$data[$type] = 1;
						$map[$key] = $pid;
						if(M($model)->where($map)->save($data)){
							$uap[$key] = $pid;
							$puser=M($model)->where($uap)->Field('uid,code,title')->find();
							$reason="上传'".$puser['title']."'";
							income($puser['uid'],10,$reason,$puser['code']);
							//$this->assign('staxm',0);
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}else{
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}
					}else{
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}
				}else{
					$modeltp = "Resource/".strtolower($model);
					$this->redirect($modeltp);
				}
			}else{
				$modeltp = "Resource/".strtolower($model);
				$this->redirect($modeltp);
			}
		}else{
			$isLogin = session(C('ADMIN_AUTH_KEY'));
			if(!$isLogin) $this->redirect('User/login');
			$pid = $_GET['pid'];
			$type = $_GET['type'];
			$model = $_GET['model'];
			$key = $_GET['key'];
			if($pid && $type && $model && $key)
			{
				$map[$key] = $pid;
				$map['is_dele'] = 0;
				$data[$type] = 1;
				if(($model == 'Article' || $model == 'Knowledge') && $type == 'status'){
					$url = M($model)->field('url')->where($map)->find();
					if($url['url']){
						import("ORG.Util.Ftp");
						$config = array(
							'hostname' => '192.168.27.232',
							'username' => 'xww',
							'password' => '123456',
							'port' => 21
						);
						$ftp = new Ftp();
						$content = $ftp->connect($config);
						if($content){
							$filename = $url['url'];
							$sourceFile = './Public/Uploads/'.$model.'/'.$filename;
							if($this->txt2utf8($sourceFile)){
								$furl = './Public/Uploads/'.$model.'/';
								$status = ($ftp->upload($furl.$filename,'word2pdf/'.$filename));
							}
							if($status){
								//echo 'http://192.168.27.232/ex/7.php?model=.'.$model.'&file='.$filename.'&pid='.$pid.'&key='.$key;
								header('Location: http://192.168.27.232/ex/7.php?model='.$model.'&file='.$filename.'&pid='.$pid."&key=".$key."&type=".$type);
								exit;
							}else{
								$modeltp = "Resource/".strtolower($model);
								$this->redirect($modeltp);
							}
						}else{
							$modeltp = "Resource/".strtolower($model);
							$this->redirect($modeltp);
						}
					}
				}else{
					$model1=M($model);
					$res = $model1->where($map)->save($data);
					$uap[$key] = $pid;
					$puser=$model1->where($uap)->Field('uid,code,title')->find();
					$reason="上传'".$puser['title']."'";
					income($puser['uid'],10,$reason,$puser['code']);
					if($res){
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}else{
						$modeltp = "Resource/".strtolower($model);
						$this->redirect($modeltp);
					}
				}
			}else{
				$modeltp = "Resource/".strtolower($model);
				$this->redirect($modeltp);
			}
		}
	}
	
	public function getSwf($sourceFile,$destFile){
			
		//echo "begin...<br/>";
			#exec("/usr/local/swftools/bin/pdf2swf qx.pdf -o ok.swf",$arrOut,$retVal);
		$pdflujing=$sourceFile.'.pdf';
		//exec("./Public/zhuanhuan/doc2pdf $sourceFile $pdflujing",$arrOut,$retVal);
		
		exec("./Public/zhuanhuan/pdf2swft $pdflujing $destFile",$arrOut,$retVal);

		return $retVal;
	}
	
	/**
	 * $filename  文件名（带文件路径）
	 * return	  true OR false
	 */
	public function txt2utf8($filename){
		if(pathinfo($filename, PATHINFO_EXTENSION) == 'txt'){
			$filedata = file_get_contents($filename); 	
			$filetype = mb_detect_encoding($filedata , array('UTF-8','GBK','LATIN1','BIG5'));
			if( $filetype != 'UTF-8'){ 
		    	$fileda = iconv($filetype ,'utf-8',$filedata);
		    	if(file_put_contents($filename , $fileda )){
		    		return true;
		    	}else{
		    		return false;
		    	}
			}else{
				return true;
			}
		}else{
			return true;
		}
	}
	
	/*
	 * 文档转换
	 * $doc 需要转换的文档
	 * $furl 文档存放路径
	 * $surl 转换后的文档存放路径
	 */
	public function convert($doc,$furl,$surl)
	{
		$docFile=$furl.$doc;//需要转换的文档           
		$newFile=$surl.$doc.".swf";//转换后的文件名        
		$command= "\"./Public/Tools/FlashPaper/FlashPrinter.exe\" ".$docFile." -o ".$newFile;        
		if(!file_exists($newFile))//swf文件已经存在就不用转换了        
			exec($command);//执行转换        
		return $newFile;    
	}
	

//验证码
	public function verify(){
    	import("ORG.Util.Image");	
		Image::buildImageVerify();
	}
	//显示资源库下的分类
	
	public function showsid(){
	    if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$pid = $_POST['pid'];
		if($pid){
			$map['catepid'] = $pid;
			$map['status'] = 1;
			$resl = M('Category')->where($map)->select();
			if($resl){
				$res = "<option value='0' selected >选择分类</option>";
				foreach ($resl as $key => $value){
					$res .= "<option value='". $value['cateid'] ."'  name='cateid'>" . $value['catename'] . "</option>";
				}
				$res="<select name='cateid' id='cateid' class='cateid' style='width:145px;'>".$res."</select>";
				echo $res;
			}else{
				//$res = "<option value='0' selected >新建分类</option>";
				echo 0;
			}
		}else{
			echo 0;
		}
	}
	public function checkverify(){
	    if(!session(C('ADMIN_AUTH_KEY')))
		$this->redirect('User/login');
		$val=md5($_POST['val']);
		if($val){
		 if($_SESSION['verify'] !=$val) echo 1;
		 else echo 0;
		}
	}
	
	/**
	* PDFtoPNG
	* @param $pdf  待处理的PDF文件
	* @param $path 待保存的图片路径
	* @return      保存好的图片文件名
	*/
	 function pdf2png($pdf,$path)
	{  
	   if(!extension_loaded('imagick'))
	   {  
	       return false;  
	   }  
	   if(!file_exists($pdf))
	   {  
	       return false;  
	   }  
	   $im = new Imagick();  
	   $im->setResolution(10,10);  
	   $im->setCompressionQuality(60);
	   $im->readImage($pdf."[0]");
	
	   foreach ($im as $Key => $Var)
	   {  
	       $Var->setImageFormat('jpg'); 
	       $filename = md5($Key.time()).'.jpg';
	       $filenames = $path."/". $filename;
	       if($Var->writeImage($filenames) == true)
	       {  
	           $Return[] = $filename;  
	       }  
	   }  
	   return $Return;  
	}
	
	/**
	 * 首页缩略图名称插入数据库
	 * @param $pid   资源id
	 * @param $model 资源类型
	 * @param $name  资源封面图名称
	 * @param $type  资源id的字段类型
	 */
	public function insertname($pid,$name,$model,$type){
		if($pid != 0 && $name && $model && $type){
			$map[$type] = $pid;
			$data['imageurl'] = $name;
			$res = M($model)->where($map)->save($data);
			if($res){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	
	public function getarr($str){

		$arr=explode('/',$str);
	
		foreach($arr as $key=>$val){
	
			if(($key%2)==0){
				$array1[] = $val;
			}else
			$array2[]=$val;	
		}
	
		$array3=array_combine($array1,$array2);
		return $array3;
	}
}